package lihua.robot.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lihua.robot.common.Result;
import lihua.robot.mapper.FallingTimeMapper;
import lihua.robot.pojo.FallingTime;
import lihua.robot.service.FallingTimeService;
import lihua.robot.utils.ApplicationContextUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author huanghan
* @description 针对表【falling_time】的数据库操作Service实现
* @createDate 2024-01-29 00:49:05
*/
@Service
public class FallingTimeServiceImpl extends ServiceImpl<FallingTimeMapper, FallingTime>
    implements FallingTimeService {

    @Override
    public Integer getSmallBucket() {
        LambdaQueryWrapper<FallingTime> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FallingTime::getArtificial,1)
                .eq(FallingTime::getArtificialStatus,1)
                .eq(FallingTime::getSmallBucketStatus,1);
        List<FallingTime> list = this.getBaseMapper().selectList(wrapper);
        if(!list.isEmpty()) {
            return list.get(0).getId();
        }
        return null;
    }

    @Override
    public Result saveFallingTime(int now_dqcd, int before_dqcd, int deSvn, int workshop, String ydid, Integer artificial, Integer artificialStatus) {
        FallingTime fallingTime = new FallingTime();
        fallingTime.setNowDqcd(now_dqcd);
        fallingTime.setBeforeDqcd(before_dqcd);
        fallingTime.setCreateTime(DateUtil.date());
        fallingTime.setDevsn(deSvn);
        fallingTime.setArtificial(artificial);
        if (ydid != null) {
            fallingTime.setYdId(ydid);
        }
        fallingTime.setSmallBucketStatus(0);
        fallingTime.setWorkshop(workshop);
        fallingTime.setArtificialStatus(artificialStatus);
        this.save(fallingTime);
        return Result.success("保存成功");
    }
}




